<?php namespace app\home\controller;

class Entry extends Common {

	public function index() {
        //处理title
        $conf = ['title' => 'CheliOus教学博客-首页'];
        View::with('conf', $conf);
        $data = Db::table('article')
                ->where('is_recycle',0)
                ->orderBy('sendtime','desc')
                ->paginate(5);
        $page = $data->links();
        $data = $data->toArray();
//        p($data);
        //关联分类表
        foreach ($data as $k => $v){
            //加上cname字段
            $data[$k]['cname'] = Db::table('category')
                                ->where('cid',$v['category_cid'])
                                ->pluck('cname');
        }
//        p($data);
        //关联标签表
        foreach ($data as $k => $v){
            //加上标签信息
            $data[$k]['tag'] = Db::table('article_tag')
                                ->join('tag','article_tag.tag_tid','=','tag.tid')
                                ->where('article_tag.article_aid',$v['aid'])
                                ->field(['tid','tname'])
                                ->get();
        }
//        p($data);
        View::with('data', $data)->with('page', $page);

		return view();
	}

}